package com.zbvc.web;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.zbvc.dao.BookDao;
import com.zbvc.dao.impl.BookDaoImpl;

/**
 * Servlet implementation class DeleteBookServlet
 */
@WebServlet(name = "deleteBook", urlPatterns = { "/deleteBook" })
public class DeleteBookServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;

	/**
	 * @see HttpServlet#HttpServlet()
	 */
	public DeleteBookServlet() {
		super();
		// TODO Auto-generated constructor stub
	}

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse
	 *      response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		// 删除书籍
		// 防止中文乱码
		request.setCharacterEncoding("UTF-8");
		response.setContentType("text/html;charset=UTF-8");
		// 获取要删除的书籍id
		int bid =Integer.parseInt(request.getParameter("bid"));
		BookDao bookDao = new BookDaoImpl();
		int row = bookDao.deleteBookById(bid);
		if(row>0) {
			System.out.println("删除成功");
			response.sendRedirect("/bookManager/admin/admin_book.jsp");
		}else {
			System.out.println("删除失败");
		}
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse
	 *      response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		// TODO Auto-generated method stub
		doGet(request, response);
	}

}
